#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "header.h"



int main(int argc, char** argv, char** argenv){


  char* c;
  int j;
  int cmp;
  int index_text;
  char* text;
  char * keys;
  int* flags;
  int i;

 


  if ((argc>7) || (argc<5))
    {
      fprintf(stderr,"Erreur, nombre de paramètres incorrect.\n\n");
      usage_vigenere();
      exit(1);
    }

  flags=(int*) malloc (sizeof(int)*4);
  j=1;
  cmp=-1;
  index_text=-1;

 for (i=0;i<4;i++)
    flags[i]=0;

  traitement_vigenere(argc,argv,j,cmp,&index_text,&text,&keys,&flags);
  


  if ((flags[0]==0) && (flags[3]==0))
    {
      fprintf(stderr,"Erreur,Pas de clé fournie.\n\n");
      usage_vigenere();
      exit(5);
    } 


  if ((flags[1]==0) && (flags[2]==0))
    {
      fprintf(stderr,"Erreur, pas de texte à crypter fourni.\n\n");
      usage_vigenere();
      exit(6);
    }


 
  c=vigenere(text,keys);
  
  affichage(c);
  
  


  
  free(flags);
  free(c);
  exit(0);	
  
}
  


